package com.ruoyi.pims.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.pims.domain.HealthDiet;
import com.ruoyi.pims.service.IHealthDietService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 饮食数据管理Controller
 * 
 * @author useragent-1
 * @date 2025-05-16
 */
@Controller
@RequestMapping("/pims/diet")
public class HealthDietController extends BaseController
{
    private String prefix = "pims/diet";

    @Autowired
    private IHealthDietService healthDietService;

    @RequiresPermissions("pims:diet:view")
    @GetMapping()
    public String diet()
    {
        return prefix + "/diet";
    }

    /**
     * 查询饮食数据管理列表
     */
    @RequiresPermissions("pims:diet:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(HealthDiet healthDiet)
    {
        startPage();
        List<HealthDiet> list = healthDietService.selectHealthDietList(healthDiet);
        return getDataTable(list);
    }

    /**
     * 导出饮食数据管理列表
     */
    @RequiresPermissions("pims:diet:export")
    @Log(title = "饮食数据管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(HealthDiet healthDiet)
    {
        List<HealthDiet> list = healthDietService.selectHealthDietList(healthDiet);
        ExcelUtil<HealthDiet> util = new ExcelUtil<HealthDiet>(HealthDiet.class);
        return util.exportExcel(list, "饮食数据管理数据");
    }

    /**
     * 新增饮食数据管理
     */
    @RequiresPermissions("pims:diet:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存饮食数据管理
     */
    @RequiresPermissions("pims:diet:add")
    @Log(title = "饮食数据管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(HealthDiet healthDiet)
    {
        return toAjax(healthDietService.insertHealthDiet(healthDiet));
    }

    /**
     * 修改饮食数据管理
     */
    @RequiresPermissions("pims:diet:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        HealthDiet healthDiet = healthDietService.selectHealthDietById(id);
        mmap.put("healthDiet", healthDiet);
        return prefix + "/edit";
    }

    /**
     * 修改保存饮食数据管理
     */
    @RequiresPermissions("pims:diet:edit")
    @Log(title = "饮食数据管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(HealthDiet healthDiet)
    {
        return toAjax(healthDietService.updateHealthDiet(healthDiet));
    }

    /**
     * 删除饮食数据管理
     */
    @RequiresPermissions("pims:diet:remove")
    @Log(title = "饮食数据管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(healthDietService.deleteHealthDietByIds(ids));
    }
}
